<style lang="sass" scoped>
        .img{
        width:120px;
    }
</style>
<template>
    <div v-jurdie="'book1100'" class="container">
        <div class="search-cont">
            <el-input placeholder="请搜索" v-model.trim="search.keyWord">
                <i slot="prefix" class="el-input__icon el-icon-search"></i>
            </el-input>
            <el-select v-model="search.categId" placeholder="请选择类目">
                <el-option v-for="product in categlist" :key="product.categId" :label="product.categName" :value="product.categId">
                </el-option>
            </el-select>
            <el-button @click="getList()" type="primary" :plain="false">搜索</el-button>
            <el-button v-jurdie="'book1101'" @click="routerGo('product_add')" type="primary" :plain="false">新增</el-button>
        </div>
        <div class="tabs-cont">
            <el-button
                @click="search.status=''" 
                :type="search.status===''?'primary':''">全部</el-button>
            <el-button
                @click="search.status=0" 
                :type="search.status===0?'primary':''">未审核</el-button>
            <el-button
                @click="search.status=1" 
                :type="search.status===1?'primary':''">已审核</el-button>
        </div>
        <div class="table-cont">
            <el-table :data="list" style="width: 100%">
                <el-table-column label="商品图片">
                    <template slot-scope="props">
                        <img class="img" v-if="props.row.mainImageUrl" :src="props.row.mainImageUrl">
                    </template>
                </el-table-column>
                <el-table-column prop="productCode" label="商品编码">
                </el-table-column>
                <el-table-column prop="productName" label="商品名称">
                </el-table-column>
                <el-table-column prop="categName" label="类目">
                </el-table-column>
                <el-table-column prop="createTime" label="创建时间">
                </el-table-column>
                <el-table-column width="260" label="操作">
                    <template slot-scope="props">
                        <el-button v-jurdie="'book1102'" @click="routerGo('product_add',{productCode:props.row.productCode})" type="primary" :plain="false" size="small">修改</el-button>
                        <el-button v-jurdie="'book1103'" @click="deleteProduct(props.row)" type="danger" :plain="false" size="small">作废</el-button>
                        <el-button v-jurdie="'book1104'" @click="modifyStatus(props.row)"  v-if="props.row.status===0" type="primary" :plain="false" size="small">审核</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <el-pagination background layout="total, prev, pager, next" :total="search.total" @current-change="handleCurrentChange">
            </el-pagination>
        </div>
    </div>
</template>
<script>
    export default {
        components: {
        },
        data() {
            return {
                //列表搜索参数
                search:{
                    keyWord:'', //	是	string	搜索关键字
                    status:'', //	是	string	状态，0-未审核，1-已审核
                    categId:'', //	是	string	类目ID
                    pageNo:1, //	是	string	页码
                    pageSize:config.pageSize, //	是	string	当前页显示的条数
                    total:0,
                },
                list:[],
                selectValue:'',
                categlist:[]
            };
        },
        watch:{
            'search.status'(val){
                this.getList();
            }
        },
        created(){
            server.getCategList().then(res=>{
                this.categlist = res;
            })
        },
        mounted() {
            this.$nextTick(() => {
                this.getList();
            });
        },
        methods: {
            handleCurrentChange(val) {
                this.search.pageNo = val;
                this.getList();
            },
            getList() {
                let param = JSON.parse(JSON.stringify(this.search));
                util.ajax({
                    url: config.baseApi + "bookMall-admin/api/product/getProductListPage",
                    data: param,
                    success: data => {
                        this.list = data.data.record;
                        this.search.total = data.data.totalNum;
                    }
                });
            },
            deleteProduct(item){
                popup.confirm({
                    content:'是否作废该产品？',
                    yes:()=>{
                        util.ajax({
                            url: config.baseApi + "bookMall-admin/api/product/deleteProduct",
                            data: {
                                productCode:item.productCode
                            },
                            success: data => {
                                popup.miss({content:'操作成功！'});
                                this.getList();
                            }
                        });
                    }
                })
            },
            //审核
            modifyStatus(item){
                popup.confirm({
                    content:'是否通过审核？',
                    yes:()=>{
                        util.ajax({
                            url:config.baseApi + 'bookMall-admin/api/product/modifyStatus',
                            data:{
                                productCode:item.productCode,
                                status:1,
                            },
                            success:(data=>{
                                popup.miss({content:'审核成功！'});
                                this.getList();
                            })
                        })
                    }
                })
            }
        },
        
    };
</script>